package mywebapps.jsf;

import java.io.File;

import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;

import mywebapps.common.jsf.ImagesUtil;
import mywebapps.dao.ArtProductDao;
import mywebapps.model.ArtProduct;

@Named("deleteArtProductBean")
@RequestScoped
public class DeleteArtProductAction {
    @Inject private ArtProductDao artProductDao;
    
    public void setArtProductDao(ArtProductDao artProductDao) {
		this.artProductDao = artProductDao;
	}

    public void deleteArtProduct(ArtProduct artProduct) {
	    artProductDao.deleteById(artProduct.getArtProductId());
	    String path = "";
		if(artProduct.getType().compareTo("PAINTING") == 0) {
			path = ImagesUtil.getPaintingsPath();
		} else
		if(artProduct.getType().compareTo("SKETCH") == 0) {
			path = ImagesUtil.getSketchesPath();
		} else
		if(artProduct.getType().compareTo("PHOTOGRAPH") == 0) {
			path = ImagesUtil.getPhotographsPath();
		}
		
		File file = new File(path + "/" + artProduct.getFilename());
		file.delete();
    }
}
